Skip to content

Fix: bound explicit EC-domain field lengths to prevent buffer overflow - #11273

Open
jackctj117 wants to merge 2 commits into
wolfSSL:masterfrom
jackctj117:11288
Open

Fix: bound explicit EC-domain field lengths to prevent buffer overflow#11273
jackctj117 wants to merge 2 commits into
wolfSSL:masterfrom
jackctj117:11288

Conversation

@jackctj117

Copy link
Copy Markdown
Contributor

This pull request addresses a security issue (issue 11288) related to potential buffer overflows when decoding explicit EC domain parameters from DER-encoded data. The main change is to ensure that all explicit-parameter field lengths (prime, coordinate, A, B, and order) are properly bounded to prevent overflows. It also adds regression tests to verify the fix and prevent future regressions.

Security and correctness improvements:

  • Added a length check in EccSpecifiedECDomainDecode to reject DER-encoded EC domain parameters with field lengths exceeding MAX_ECC_BYTES, preventing buffer overflows and ensuring safe handling of explicit EC-domain parameters.

Testing and regression coverage:

  • Added a new regression test function test_wc_EccPublicKeyDecode_specifiedOverflow in test_ecc.c that builds DER-encoded EC public keys with oversized fields to verify that the new length checks correctly reject them, and that boundary cases are accepted.
  • Declared the new regression test in test_ecc.h and included it in the ECC test group for automated test runs. [1] [2]
  • Added a similar regression test (ecc_ssdd_overflow_test) in wolfcrypt/test/test.c for additional coverage, including helper functions for DER construction, and integrated it into the main ECC test routine. [1] [2]

These changes collectively harden the ECC decoding logic against malformed or malicious input and ensure that future changes will be tested for this class of vulnerability.

Copilot AI lite review requested due to automatic review settings August 25, 2026 22:20
@wolfSSL-Bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens explicit EC-domain parameter decoding against malformed DER that could trigger buffer overflows when converting explicit parameters (prime, A, B, order, and derived base-point coordinates) into fixed-size hex-string buffers.

Changes:

  • Added explicit field-length bounds in EccSpecifiedECDomainDecode() to reject DER explicit-parameter fields larger than MAX_ECC_BYTES.
  • Added regression tests that construct explicit-parameter SubjectPublicKeyInfo blobs with oversized fields and verify rejection with ASN_PARSE_E.
  • Integrated the new regression test into both the API test suite and wolfcrypt/test/test.c ECC tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
wolfcrypt/src/asn.c Adds MAX_ECC_BYTES bounds for explicit EC-domain fields during template-based ASN decoding.
tests/api/test_ecc.c Adds API-level regression test that builds explicit-parameter SPKI inputs and checks acceptance/rejection behavior.
tests/api/test_ecc.h Declares and registers the new API regression test in the ECC test group.
wolfcrypt/test/test.c Adds a second regression test variant in the wolfCrypt test harness and wires it into ecc_test().

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/api/test_ecc.c
Comment thread wolfcrypt/test/test.c
Comment on lines +46418 to +46425
{
byte pub[68];
pub[0] = 0x00;
pub[1] = 0x04;
for (i = 0; i < 32; i++) pub[2 + i] = 0x44;
for (i = 0; i < 32; i++) pub[34 + i] = 0x55;
bo = ecc_ssdd_tlv(body, bo, 0x03, pub, 66); /* pubkey BIT STRING */
}
Comment thread wolfcrypt/src/asn.c

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #11273

Scan targets checked: wolfcrypt-bugs, wolfcrypt-port-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

Findings: 6
6 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread tests/api/test_ecc.c Outdated
Comment thread wolfcrypt/test/test.c
static const byte cof1[1] = { 0x01 };
byte num[512];
byte inner[1024];
byte body[2048];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DER builder puts 3.6 KB of fixed buffers on the stack in wolfcrypt/test/test.c · Buffer safety in test payload builders

num[512], inner[1024] and body[2048] add ~3.6 KB to the stack frame in ecc_test()'s call chain, unguarded by WOLFSSL_SMALL_STACK. test.c is compiled into MCU targets as a smoke test and heap-allocates buffers as small as 1280 bytes there; this frame overflows such stacks. The actual maximum needed is a few hundred bytes.

Fix: Right-size the buffers to the required maximum or allocate them from HEAP_HINT under WOLFSSL_SMALL_STACK, as elsewhere in test.c.

Comment thread wolfcrypt/test/test.c
Comment thread tests/api/test_ecc.c Outdated
Comment thread tests/api/test_ecc.c Outdated
Comment thread tests/api/test_ecc.c Outdated
@philljj philljj assigned jackctj117 and unassigned wolfSSL-Bot Aug 27, 2026
@jackctj117
jackctj117 marked this pull request as ready for review August 28, 2026 19:18
@github-actions

Copy link
Copy Markdown

retest this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants